<?php

namespace Standard\Bundle\ModuleAboutBundle\Services;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container;

abstract class BookPrototype {
    protected $title;
    protected $topic;
    abstract function __clone();
    function getTitle() {
        return $this->title;
    }
    function setTitle($titleIn) {
        $this->title = $titleIn;
    }
    function getTopic() {
        return $this->topic;
    }
}

class PHPBookPrototype extends BookPrototype {
    function __construct() {
        $this->topic = 'PHP contructor';
    }
    function __clone() {
        $this->topic = 'PHP clone';
    }
}

class SQLBookPrototype extends BookPrototype {
    function __construct() {
        $this->topic = 'SQL';
    }
    function __clone() {
    }
}

class PrototypeDesginPatten {
    //put your code here
    private $templating;
	
    private $router;

    private $em;

    private $container;

    public function __construct(EngineInterface $templating, 
                                UrlGeneratorInterface $router,
                                EntityManager $em, Container $container )
    {
        $this->templating = $templating;
        $this->router = $router;
        $this->em = $em;
        $this->container = $container;

    }
    
    function testDesginPatten(){
        $this->writeln('BEGIN TESTING PROTOTYPE PATTERN');
        $this->writeln('');

        $phpProto = new PHPBookPrototype();
        $sqlProto = new SQLBookPrototype();
        
        $phpProto->setTitle('SQL For Cats');
        $this->writeln('Book 1 topic: '.$phpProto->getTopic());
        $this->writeln('Book 1 title: '.$phpProto->getTitle());
        $this->writeln('');
        
        $book1 = clone $sqlProto;
        $book1->setTitle('SQL For Cats');
        $this->writeln('Book 1 topic: '.$book1->getTopic());
        $this->writeln('Book 1 title: '.$book1->getTitle());
        $this->writeln('');

        $book2 = clone $phpProto;
        $book2->setTitle('OReilly Learning PHP 5');
        $this->writeln('Book 2 topic: '.$book2->getTopic());
        $this->writeln('Book 2 title: '.$book2->getTitle());
        $this->writeln('');

        $book3 = clone $sqlProto;
        $book3->setTitle('OReilly Learning SQL');
        $this->writeln('Book 3 topic: '.$book3->getTopic());
        $this->writeln('Book 3 title: '.$book3->getTitle());
        $this->writeln('');

        $this->writeln('END TESTING PROTOTYPE PATTERN');

    }
    
    

    function writeln($line_in) {
        echo $line_in."<br/>";
    }
}
